package com.sc.nft.dao;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sc.nft.entity.SecondOrderSettle;
import com.sc.nft.enums.DivideTypeEnum;
import com.sc.nft.exception.GlobalRunTimeException;
import com.sc.nft.sup.ErrorCode;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.FirstOrderSettle;
import com.sc.nft.mapper.FirstOrderSettleMapper;
import  com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_first_order_settle)数据DAO
 *
 * @author zxy
 * @since 2023-12-06 20:29:39
 * @description 商户banner
 */
@Slf4j
@Repository
public class FirstOrderSettleDao extends ServiceImpl<FirstOrderSettleMapper, FirstOrderSettle> {


    public List<FirstOrderSettle> getWaitSettle(){
        return lambdaQuery().eq(FirstOrderSettle::getDivideType, DivideTypeEnum.DAO).eq(FirstOrderSettle::getIsSettle,false).last("limit 1000").list();
    }

    public void updateSettle(Long id){
        Assert.isTrue(lambdaUpdate().eq(FirstOrderSettle::getId,id).eq(FirstOrderSettle::getIsSettle,false).set(FirstOrderSettle::getIsSettle,true).update(),
                ()-> new GlobalRunTimeException(ErrorCode.UPDATE_ERROR));
    }
}